package mysql_models

import (
	"go-scripts/common"
	"database/sql"
	"fmt"
)

func GetMysqlModel(db string) *sql.DB {
	mysql := common.GetMysql()
	switch db {
	case "jingx":
		return mysql.Jingx
	default:
		return nil
	}
}

type ModelDao interface {
	Save()
}

func formatSaveSql(tableName string, saveValues map[string]interface{}) (string, []interface{}) {
	sql := "insert into %s ( %s ) values ( %s )"
	fields := ""
	values := ""
	pre := []interface{}{}
	for key, value := range saveValues {
		fields += ", " + key
		values += ", ?"
		pre = append(pre, value)
	}
	if fields == "" || values == "" {
		return "", pre
	}
	fields = common.SubStr(fields, 1, common.StrLength(fields))
	values = common.SubStr(values, 1, common.StrLength(values))
	return fmt.Sprintf(sql, tableName, fields, values), pre
}
